/**
 * @Copyright (c) 2007,上海友邻信息科技有限公司
 * @All rights reserved.
 *
 *
 *
 * @file_name   Notifier.js
 * @version     1.0
 * @author      黄新泽
 * @date        2008-01-16 16:30:47
 */

/**
 * Class and Function List:
 * Function list:
 * - initialize: function(time)  
 * - initObservers: function()   
 * - onInterrupt: function()     
 * - setTimer: function()        
 * - function onIdle(e)          
 * - function onActive(e)        
 * Classes list:
 * - .Notifier
 */
var Notifier = Class.create({
	
	_events: [[window, 'scroll'], [window, 'resize'], [document, 'mousemove'], [document, 'keydown']],
	_timer: null,
	_idleTime: null,
	
	initialize: function(time)
	{
		
		this.time = time;
		
		this.initObservers();
		this.setTimer();
	},
	
	initObservers: function()
	{
		this._events.each(function(e)
		{
			Event.observe(e[0], e[1], this.onInterrupt.bind(this))
		}.bind(this))
	},
	
	onInterrupt: function()
	{
		document.fire('state:active', { idleTime: new Date() - this._idleTime });
		this.setTimer();
	},
	
	setTimer: function()
	{
		clearTimeout(this._timer);
		this._idleTime = new Date();
		this._timer = setTimeout(function() {
			document.fire('state:idle');
		}, this.time)
	}
});


//document.observe('dom:loaded', function(){
	//new Notifier(5000);
	//document.observe('state:idle', onIdle).observe('state:active', onActive);
	
	//function onIdle(e)
	//{
		//console.info('onIdle');
		//$(document.body).setOpacity(0.2);
		//active = false;
	//}

	//function onActive(e)
	//{
		//console.info('onActive');
		//if (active)
		//{
			//active = true;
		//}
		//else
		//{
			//active = true;
			//$(document.body).setOpacity(1);
			//refresh_data_start();
			//refreshTabUrl();
		//}
	//}
//});


